//------------Sonic CD Sound Test Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 2: TYPE_SOUNDTEST


function SoundTest_PlayTrack
	StopMusic()
	switch Object.Value4
	case 0
				SetMusicTrack("JP/R1A.ogg",0,1)
		break
	case 1			
				SetMusicTrack("R1B.ogg",0,1)
		break
	case 2
				SetMusicTrack("JP/R1C.ogg",0,1)
		break
	case 3
				SetMusicTrack("JP/R1D.ogg",0,1)
		break
	case 4
				SetMusicTrack("JP/R3A.ogg",0,1)
		break
	case 5				
		SetMusicTrack("R3B.ogg",0,1)// Hybrid P+A
		break
	case 6
				SetMusicTrack("JP/R8C.ogg",0,1)
		break
	case 7
				SetMusicTrack("JP/R3D.ogg",0,1)
		break
	case 8
				SetMusicTrack("JP/R4A.ogg",0,1)
		break
	case 9			
				SetMusicTrack("R4B.ogg",0,1)
		break
	case 10
				SetMusicTrack("JP/R4C.ogg",0,1)
		break
	case 11
				SetMusicTrack("JP/R4D.ogg",0,1)
		break
	case 12
				SetMusicTrack("JP/R5A.ogg",0,1)
		break
	case 13
				SetMusicTrack("R5B.ogg",0,1)
		break
	case 14
				SetMusicTrack("JP/R5C.ogg",0,1)
		break
	case 15
				SetMusicTrack("JP/R5D.ogg",0,1)
		break
	case 16
				SetMusicTrack("JP/R6A.ogg",0,1)
		break
	case 17
				SetMusicTrack("R6B.ogg",0,1)// JP
		break
	case 18
				SetMusicTrack("JP/R6C.ogg",0,1)
		break
	case 19
				SetMusicTrack("JP/R6D.ogg",0,1)
		break
	case 20
				SetMusicTrack("JP/R7A.ogg",0,1)
		break
	case 21
				SetMusicTrack("R7B.ogg",0,1)// JP
		break
	case 22
				SetMusicTrack("JP/R7C.ogg",0,1)
		break
	case 23
				SetMusicTrack("JP/R7D.ogg",0,1)
		break
	case 24
				SetMusicTrack("JP/R8A.ogg",0,1)
		break
	case 25
				SetMusicTrack("R8B.ogg",0,1)
		break
	case 26
				SetMusicTrack("JP/R8C.ogg",0,1)
		break
	case 27
				SetMusicTrack("JP/R8D.ogg",0,1)
		break
	case 28
				SetMusicTrack("JP/Boss.ogg",0,1)
		break
	case 29
				SetMusicTrack("JP/Boss.ogg",0,1)
		break
	case 30
			SetMusicTrack("JP/TitleScreen.ogg",0,0)
		break
	case 31
				SetMusicTrack("JP/ZoneComplete.ogg",0,0)
		break
	case 32
				SetMusicTrack("JP/SpeedShoes.ogg",0,0)
		break
	case 33
				SetMusicTrack("JP/Invincibility.ogg",0,0)
		break
	case 34
				SetMusicTrack("JP/GameOver.ogg",0,0)
		break
	case 35
				SetMusicTrack("JP/SpecialStage.ogg",0,1)
		break
	case 36
				SetMusicTrack("JP/DAGarden.ogg",0,1)
		break
	case 37
				SetMusicTrack("JP/Menu.ogg",0,000001)
		break

	endswitch
	PlayMusic(SaveRAM[38])
endfunction


function SoundTest_CheckSecret
	if Object.Value3==4
		if Object.Value4==21
			StopMusic()
			SetMusicTrack("JP/Boss.ogg",0,1)
			Object.Value7=0
			Object.State=4
		endif
	endif
	if Object.Value3==12
		if Object.Value4==25
			StopMusic()
			SetMusicTrack("JP/Menu.ogg",0,1)
			Object.Value7=1
			Object.State=4
		endif
	endif
	if Object.Value3==11
		if Object.Value4==9
			StopMusic()
			SetMusicTrack("JP/R1C.ogg",0,1)
			Object.Value7=2
			Object.State=4
		endif
	endif
	if Object.Value3==3
		if Object.Value4==1
			StopMusic()
			SetMusicTrack("JP/R8A.ogg",0,1)
			Object.Value7=3
			Object.State=4
		endif
	endif
	if Object.Value3==12
		if Object.Value4==11
			StopMusic()
			SetMusicTrack("JP/Credits.ogg",0,1)
			Stage.DebugMode=1
			Object.Value7=4
			Object.State=4
		endif
	endif
	if Object.Value3==32
		if Object.Value4==8
			StopMusic()
			SetMusicTrack("JP/DAGarden.ogg",0,1)
			Stage.PlayerListPos=1
			Object.Value7=5
			Object.State=4
		endif
	endif
	if Object.Value3==7
		if Object.Value4==7
			StopMusic()
			PlayStageSfx(41,0)
			Object.State=5
			SetupMenu(MENU_1,0,3,1)
			AddMenuEntry(MENU_1,"WELCOME TO THE SECRET SPECIAL STAGE",1)
			CreateTempObject(TypeName[MessageText],0,Object.XPos,Object.YPos)
			Object[TempObjectPos].iXPos=Screen.CenterX
			Object[TempObjectPos].XPos+=131072
			Object[TempObjectPos].iYPos=152
		endif
	endif
endfunction


sub ObjectMain
	switch Object.State
	case 0
	LoadPalette("SoundTest.Act",0,0,0,256)
		if Object.Value0<8
			Object.Value0++
		else
			Object.Value0=254
			Object.State++
		endif
		SetScreenFade(0,0,0,255)
		break
	case 1
		if Object.Value0>0
			SetScreenFade(0,0,0,Object.Value0)
			Object.Value0-=8
		else
			Object.State++
		endif
		break
	case 2
		if Object.Value6>0
			Object.Value6--
		endif
		if Object.Value1==0
			if KeyPress.Up==1
				Object.Value2=0
				Object.Value3--
				if Object.Value3<0
					Object.Value3=69
				endif
			else
				if KeyPress.Down==1
					Object.Value2=0
					Object.Value3++
					if Object.Value3>69
						Object.Value3=0
					endif
				endif
			endif
			if KeyDown.Up==1
				Object.Value2++
				if Object.Value2==8
					Object.Value2=0
					Object.Value3--
					if Object.Value3<0
						Object.Value3=69
					endif
				endif
			else
				if KeyDown.Down==1
					Object.Value2++
					if Object.Value2==8
						Object.Value2=0
						Object.Value3++
						if Object.Value3>69
							Object.Value3=0
						endif
					endif
				endif
			endif
			if KeyPress.Left==1
				Object.Value1=1
			endif
			if KeyPress.Right==1
				Object.Value1=1
			endif
			TempValue0=KeyPress.ButtonA
			TempValue0|=KeyPress.ButtonB
			TempValue0|=KeyPress.ButtonC
			if TempValue0==1
				CallFunction(SoundTest_CheckSecret)
				if Object.State==2
					PlaySfx(Object.Value3,0)
					StopMusic()
				endif
			endif
		else
			if KeyPress.Up==1
				Object.Value2=0
				Object.Value4--
				if Object.Value4<0
					Object.Value4=37
				endif
			else
				if KeyPress.Down==1
					Object.Value2=0
					Object.Value4++
					if Object.Value4>37
						Object.Value4=0
					endif
				endif
			endif
			if KeyDown.Up==1
				Object.Value2++
				if Object.Value2==8
					Object.Value2=0
					Object.Value4--
					if Object.Value4<0
						Object.Value4=37
					endif
				endif
			else
				if KeyDown.Down==1
					Object.Value2++
					if Object.Value2==8
						Object.Value2=0
						Object.Value4++
						if Object.Value4>37
							Object.Value4=0
						endif
					endif
				endif
			endif
			if KeyPress.Left==1
				Object.Value1=0
			endif
			if KeyPress.Right==1
				Object.Value1=0
			endif
			TempValue0=KeyPress.ButtonA
			TempValue0|=KeyPress.ButtonB
			TempValue0|=KeyPress.ButtonC
			if TempValue0==1
				if Object.Value6==0
					CallFunction(SoundTest_CheckSecret)
					if Object.State==2
						CallFunction(SoundTest_PlayTrack)
						Object.Value6=60
					endif
				endif
			endif
		endif
		if KeyPress.Start==1
			CallFunction(SoundTest_CheckSecret)
			if Object.State==2
				StopMusic()
				Object.State++
			endif
		endif
#platform: Mobile
		TempValue0=Screen.CenterX
		TempValue0-=126
		TempValue1=Screen.CenterX
		TempValue1-=66
		CheckTouchRect(TempValue0,20,TempValue1,72)
		if CheckResult>-1
			Object.Value1=0
			KeyDown.Up=1
			Object.Value2++
			if Object.Value2==8
				Object.Value2=0
				Object.Value3--
				if Object.Value3<0
					Object.Value3=69
				endif
			endif
		endif
		CheckTouchRect(TempValue0,134,TempValue1,186)
		if CheckResult>-1
			Object.Value1=0
			KeyDown.Down=1
			Object.Value2++
			if Object.Value2==8
				Object.Value2=0
				Object.Value3++
				if Object.Value3>69
					Object.Value3=0
				endif
			endif
		endif
		TempValue0=Screen.CenterX
		TempValue0+=66
		TempValue1=Screen.CenterX
		TempValue1+=126
		CheckTouchRect(TempValue0,20,TempValue1,72)
		if CheckResult>-1
			Object.Value1=1
			KeyDown.Up=1
			Object.Value2++
			if Object.Value2==8
				Object.Value2=0
				Object.Value4--
				if Object.Value4<0
					Object.Value4=37
				endif
			endif
		endif
		CheckTouchRect(TempValue0,134,TempValue1,186)
		if CheckResult>-1
			Object.Value1=1
			KeyDown.Down=1
			Object.Value2++
			if Object.Value2==8
				Object.Value2=0
				Object.Value4++
				if Object.Value4>37
					Object.Value4=0
				endif
			endif
		endif
		if Engine.Message==2
			Object.Value5=0
		endif
		TempValue0=Screen.CenterX
		TempValue0-=22
		TempValue1=Screen.CenterX
		TempValue1+=22
		CheckTouchRect(TempValue0,116,TempValue1,140)
		if CheckResult>-1
			Object.Value5=1
		else
			CheckTouchRect(0,0,Screen.XSize,Screen.YSize)
			if CheckResult<0
				if Object.Value5==1
					Object.Value5=0
					CallFunction(SoundTest_Function1)
					if Object.State==2
						if Object.Value1==0
							PlaySfx(Object.Value3,0)
						else
							if Object.Value6==0
								CallFunction(SoundTest_Function0)
								Object.Value6=60
							endif
						endif
					endif
				endif
			else
				if Object.Value5==1
					Object.Value5=0
				endif
			endif
		endif
		CheckTouchRect(TempValue0,148,TempValue1,172)
		if CheckResult>-1
			Object.Value5=2
		else
			CheckTouchRect(0,0,Screen.XSize,Screen.YSize)
			if CheckResult<0
				if Object.Value5==2
					Object.Value5=0
					StopMusic()
				endif
			else
				if Object.Value5==2
					Object.Value5=0
				endif
			endif
		endif
		CheckTouchRect(TempValue0,180,TempValue1,204)
		if CheckResult>-1
			Object.Value5=3
		else
			CheckTouchRect(0,0,Screen.XSize,Screen.YSize)
			if CheckResult<0
				if Object.Value5==3
					Object.Value5=0
					PlaySfx(27,0)
					Object.State++
					StopMusic()
				endif
			else
				if Object.Value5==3
					Object.Value5=0
				endif
			endif
		endif
#endplatform
		break
	case 3
		if Object.Value0<288
			Object.Value0+=8
		else
			Options.GameMode=0
			Stage.ListPos=1
			LoadStage()
		endif
		TempValue0=Object.Value0
		if TempValue0>255
			TempValue0=255
		endif
		SetScreenFade(0,0,0,TempValue0)
		break
	case 4
		if Object.Value0<288
			Object.Value0+=16
		else
			Object.Type=TypeName[BlankObject]
			LoadPalette("Secrets.act",0,0,0,256)
			if Object.Value7>4
				CreateTempObject(TypeName[SecretImage2],0,Object.XPos,Object.YPos)
			else
				CreateTempObject(TypeName[SecretImage],Object.Value7,Object.XPos,Object.YPos)
			endif
		endif
		SetScreenFade(0,0,0,Object.Value0)
		break
	case 5
		if Object.Value0<120
			Object.Value0++
		else
			Object.Value0=0
			Object.State++
			PlaySfx(19,0)
		endif
		break
	case 6
		if Object.Value0<1024
			Object.Value0+=8
		else
			Object.Type=TypeName[BlankObject]
			Fade_Colour=208
			Fade_Colour<<=16
			TempValue0=255
			TempValue0<<=8
			Fade_Colour+=TempValue0
			Fade_Colour+=224
			Options.GameMode=0
			Stage.ListPos=7
			Stage.ActiveList=SPECIAL_STAGE
			LoadStage()
		endif
		SetScreenFade(208,255,224,Object.Value0)
		break

	endswitch
endsub


sub ObjectDraw
	TempValue0=0
	while TempValue0<240
		TempValue1=0
		while TempValue1<Screen.XSize
			DrawSpriteScreenXY(15,TempValue1,TempValue0)
			TempValue1+=224
		loop
		TempValue0+=48
	loop
	DrawSpriteScreenXY(16,Screen.CenterX,64)
	TempValue0=Screen.CenterX
	TempValue0-=118
	if Object.Value1==0
		DrawSpriteScreenXY(11,TempValue0,96)
	else
		DrawSpriteScreenXY(10,TempValue0,96)
	endif
	TempValue0+=56
	TempValue1=Object.Value3
	TempValue1/=10
	DrawSpriteScreenXY(TempValue1,TempValue0,96)
	TempValue0+=8
	TempValue1=Object.Value3
	TempValue1%=10
	DrawSpriteScreenXY(TempValue1,TempValue0,96)
	TempValue0+=102
	if Object.Value1==1
		DrawSpriteScreenXY(13,TempValue0,96)
	else
		DrawSpriteScreenXY(12,TempValue0,96)
	endif
	TempValue0+=48
	TempValue1=Object.Value4
	TempValue1/=10
	DrawSpriteScreenXY(TempValue1,TempValue0,96)
	TempValue0+=8
	TempValue1=Object.Value4
	TempValue1%=10
	DrawSpriteScreenXY(TempValue1,TempValue0,96)
#platform: Mobile
	if Object.State<5
		TempValue0=Screen.CenterX
		TempValue0-=96
		if Object.Value1==0
			if KeyDown.Up==1
				DrawSpriteScreenXY(18,TempValue0,48)
			else
				DrawSpriteScreenXY(17,TempValue0,48)
			endif
			if KeyDown.Down==1
				DrawSpriteScreenXY(20,TempValue0,160)
			else
				DrawSpriteScreenXY(19,TempValue0,160)
			endif
		else
			DrawSpriteScreenXY(17,TempValue0,48)
			DrawSpriteScreenXY(19,TempValue0,160)
		endif
		TempValue0+=192
		if Object.Value1==1
			if KeyDown.Up==1
				DrawSpriteScreenXY(18,TempValue0,48)
			else
				DrawSpriteScreenXY(17,TempValue0,48)
			endif
			if KeyDown.Down==1
				DrawSpriteScreenXY(20,TempValue0,160)
			else
				DrawSpriteScreenXY(19,TempValue0,160)
			endif
		else
			DrawSpriteScreenXY(17,TempValue0,48)
			DrawSpriteScreenXY(19,TempValue0,160)
		endif
		TempValue0=128
		if Object.Value5==1
			DrawSpriteScreenXY(22,Screen.CenterX,TempValue0)
		else
			DrawSpriteScreenXY(21,Screen.CenterX,TempValue0)
		endif
		TempValue0+=32
		if Object.Value5==2
			DrawSpriteScreenXY(24,Screen.CenterX,TempValue0)
		else
			DrawSpriteScreenXY(23,Screen.CenterX,TempValue0)
		endif
		TempValue0+=32
		if Object.Value5==3
			DrawSpriteScreenXY(26,Screen.CenterX,TempValue0)
		else
			DrawSpriteScreenXY(25,Screen.CenterX,TempValue0)
		endif
	endif
#endplatform
endsub


sub ObjectStartup
	LoadSpriteSheet("Secrets/SecretMenus.gif")
	SpriteFrame(0,0,8,16,1,49)
	SpriteFrame(0,0,8,16,10,49)
	SpriteFrame(0,0,8,16,19,49)
	SpriteFrame(0,0,8,16,28,49)
	SpriteFrame(0,0,8,16,1,66)
	SpriteFrame(0,0,8,16,10,66)
	SpriteFrame(0,0,8,16,19,66)
	SpriteFrame(0,0,8,16,28,66)
	SpriteFrame(0,0,8,16,1,83)
	SpriteFrame(0,0,8,16,10,83)
	SpriteFrame(0,0,56,16,136,83)
	SpriteFrame(0,0,56,16,136,100)
	SpriteFrame(0,0,48,16,193,83)
	SpriteFrame(0,0,48,16,193,100)
	SpriteFrame(0,0,8,16,19,83)
	SpriteFrame(0,0,224,48,0,0)
	SpriteFrame(-40,0,96,16,136,49)
	SpriteFrame(-10,-10,20,20,136,117)
	SpriteFrame(-10,-10,20,20,136,138)
	SpriteFrame(-10,-10,20,20,157,117)
	SpriteFrame(-10,-10,20,20,157,138)
	SpriteFrame(-20,-10,40,20,200,201)
	SpriteFrame(-20,-10,40,20,200,222)
	SpriteFrame(-20,-10,40,20,159,201)
	SpriteFrame(-20,-10,40,20,159,222)
	SpriteFrame(-20,-10,40,20,200,159)
	SpriteFrame(-20,-10,40,20,200,180)
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
